function [this, assigned] = myfile2model(this, fileName, opt, optimalOpt)
% myfile2model  [Not a public function] Translate model file to model object properties.
%
% Backend IRIS function.
% No help provided.

% -IRIS Toolbox.
% -Copyright (c) 2007-2015 IRIS Solutions Team.

%--------------------------------------------------------------------------

% Run the preparser.
[code, this.FName, this.Export, ctrlParameters, this.Comment] = ...
    preparser.Preparser.parse(fileName, [ ], opt.assign, opt.saveas, '');

% Save exportables; they must be available before we run myparse( ) because
% we check for syntax error by evaluating the equations.
export(this);

% Create database of parameters occurring in control expressions in model
% file.
d = struct( );
for i = 1 : length(ctrlParameters)
    name = ctrlParameters{i};
    d.(name) = opt.assign.(name);
end
this.PSet = d;

% Run the parser.
the = theparser('model', this.FName, code, opt.assign);
[S, assigned] = parse(the, opt);

% Parse the model object proper.
this = myparse(this, S, opt, optimalOpt);

end
